#ifndef PREC_MATRIX_H_
#define PREC_MATRIX_H_

#include "debug_functions.h"
#include "grammar_tokens.h"
#include "parsing_context.h"

#define ROW_LEN ((TERM_LEN & 0x3) == 0 ? (TERM_LEN >> 2) : (TERM_LEN >> 2) + 1) /**< Length of a row of the precedence matrix measured in bytes. */

#define PRECEDENCE(matrix, i, j) ((prec_rel)((((matrix)[gr_term_key(i)*ROW_LEN + (gr_term_key(j) >> 2)]) >> (6 - 2*(gr_term_key(j) & 0x03))) & 0x03))

typedef enum prec_rel {
  EQ = 0, GT, LT, ND, NOP
} prec_rel;

extern const char *prec_name[5];

void init_prec_name();

void init_tex_prec_name();

void generate_precedence_matrix(parsing_ctx *ctx);

void print_matrix(parsing_ctx *ctx);

void print_tex_matrix(parsing_ctx *ctx);

#endif
